﻿using JYB.SummitExam.IDAL;
using JYB.SummitExam.Model;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JYB.SummitExam.DAL
{
    public class SystemUserDAL : IUserDAL
    {
        public T Login<T>(string name, string pwd)
        {
            return Common.Common.Login<T>(name, pwd);
        }

        public static string connString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString();
        /// <summary>
        /// 学生个人信息
        /// </summary>
        /// <returns></returns>
        public List<Model.SystemUserModel> GetStudentList(int id)
        {
            #region 获取学生信息列表
            string sql = @"select a.Name, Student_Sex,Course_Name,a.Student_Tel,b.Name as TeacherName from SystemStudents a 
                                    join SystemTeacher  b on a.Teacher_Id=b.ID
                                    join SystemCollege c on a.College_Id=c.ID
                                    join SystemMajor d on  d.ID=a.College_Id
                                    join SystemCourse e on  a.Course_Id=e.ID
                                    where a.ID=@id";
            using (SqlConnection con = new SqlConnection(connString))
            {
                con.Open();
                SqlCommand com = new SqlCommand(sql, con);
                com.Parameters.Add(new SqlParameter("@id", id));
                SqlDataAdapter adap = new SqlDataAdapter(com);
                DataTable table = new DataTable();
                adap.Fill(table);
                List<SystemUserModel> list = new List<SystemUserModel>();
                foreach (DataRow item in table.Rows)
                {
                    SystemUserModel user = new SystemUserModel();
                    user.StudentName = item["Name"].ToString();
                    user.Student_Sex = item["Student_Sex"].ToString();
                    user.Course_Name = item["Course_Name"].ToString();
                    user.Student_Tel = item["Student_Tel"].ToString();
                    user.TeacherName = item["TeacherName"].ToString();
                    list.Add(user);
                }
                return list;
            }

        }
            #endregion

    }
}
